﻿using System;
using System.Collections.Generic;
using Luna.Data.Test;
using NUnit.Framework;

namespace Luna.Data.Budget
{
    internal class LineTest : DataTest<IBudgetProvider, ILineData>
    {
        private const string CODE = "Code";

        private const string DESCRIPTION = "Description";

        private const string NAME = "Name";

        private BudgetTest Budget;

        private CategoryTest Category;

        public LineTest(string contextName)
            : base(contextName)
        {
            Budget = new BudgetTest(contextName);
            Category = new CategoryTest(contextName);
        }

        public override Action<Guid> Delete
        {
            get { return Service.LineDelete; }
        }

        public override Predicate<ILineData> DeletePredicate
        {
            get { return x => x.Name.StartsWith(TEST_PREFIX); }
        }

        public override Func<Guid, ILineData> Get
        {
            get { return Service.LineGet; }
        }

        public override Func<IEnumerable<ILineData>> GetAll
        {
            get { return Service.LineGetAll; }
        }

        public override Action<ILineData> Save
        {
            get { return Service.LineSave; }
        }

        public override bool AreSame(ILineData P_Entity1, ILineData P_Entity2)
        {
            bool L_Return = true;

            L_Return &= P_Entity1.PK == P_Entity2.PK;
            L_Return &= P_Entity1.Name == P_Entity2.Name;
            L_Return &= P_Entity1.Amount == P_Entity2.Amount;
            L_Return &= P_Entity1.BudgetID == P_Entity2.BudgetID;
            L_Return &= P_Entity1.CategoryID == P_Entity2.CategoryID;
            L_Return &= P_Entity1.Code == P_Entity2.Code;
            L_Return &= P_Entity1.ParentID == P_Entity2.ParentID;
            L_Return &= P_Entity1.Description == P_Entity2.Description;

            return L_Return;
        }

        [TearDown]
        public override void Clean()
        {
            base.Clean();

            Budget.Clean();
            Category.Clean();
        }

        public override ILineData Create()
        {
            ILineData L_Entity = base.Create();
            L_Entity.PK = Guid.NewGuid();
            L_Entity.Name = GetString(NAME);
            L_Entity.Code = GetString(CODE);
            L_Entity.Amount = GetDecimal();
            L_Entity.CategoryID = GetBoolean() ? (Guid?)BUDGET_CATEGORY : null;
            L_Entity.BudgetID = BUDGET;
            L_Entity.Description = GetString(DESCRIPTION);
            return L_Entity;
        }

        [SetUp]
        public void SetUp()
        {
            Budget.CreateTestData();
            Category.CreateTestData();
        }
    }
}